package socket.socket_1;

import java.io.*;
import java.net.Socket;
import java.nio.charset.StandardCharsets;
import java.util.Scanner;

public class Client {
    private Socket socket;
   public Client (){
       try {
           System.out.println("正在启动服务端....");
           socket = new Socket("localHost",8088);
           System.out.println( "服务端启动完毕");
       } catch (IOException e) {
           e.printStackTrace();
       }
   }
    public void start(){
        OutputStream out = null;
        try {
            out = socket.getOutputStream();
        } catch (IOException e) {
            e.printStackTrace();
        }
        OutputStreamWriter osw = new OutputStreamWriter(out, StandardCharsets.UTF_8);
        BufferedWriter bw = new BufferedWriter(osw);// 字符缓冲输出流
        PrintWriter pw = new PrintWriter(bw,true);
        Scanner sc = new Scanner(System.in);
        System.out.println("输入exit表示退出，请开始输入数据：");

        while (true){
            String data = sc.nextLine();
            if ("exit".equalsIgnoreCase(data)){
                break;
            }
            pw.println(data);
        }
    }
    public static void main(String[] args) {
        Client client = new Client();
        client.start();
    }
}
